package com.example.jack.community.view.me.per_setting;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.jack.community.R;
import com.example.jack.community.view.me.BlackStatusActivity;
import com.example.jack.community.view.me.util.DemoPushService;
import com.igexin.sdk.PushManager;
import com.suke.widget.SwitchButton;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 新消息通知界面
 * 使用了第三方开关控件:https://github.com/zcweng/SwitchButton
 */
public class New_MesActivity extends BlackStatusActivity {

    //是否接受新消息
    @BindView(R.id.swh_acc_new)
    SwitchButton swhAccNew;
    @BindView(R.id.img_back)
    ImageView imgBack;
    @BindView(R.id.txt_return)
    TextView txtReturn;
    public  PushManager pushManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new__mes);
        ButterKnife.bind(this);
        switchs();//开关
    }

    /**
     * 初始化个推消息推送
     */
    private void init() {
        pushManager.getInstance().initialize(this.getApplicationContext(), DemoPushService.class);
        // com.getui.demo.DemoIntentService 为第三方自定义的推送服务事件接收类
        pushManager.getInstance().initialize(this.getApplicationContext(), DemoPushService.class);
    }

    /**
     * 开关设置
     */
    private void switchs() {

        swhAccNew.setOnCheckedChangeListener(new SwitchButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(SwitchButton view, boolean isChecked) {
                //TODO do your job
                if (isChecked) {
                    init();
                } else {
                    pushManager.getInstance().stopService(New_MesActivity.this);//停止服务
                }
            }
        });
    }

    @OnClick({R.id.img_back, R.id.txt_return})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back://返回按钮
                finish();
                break;
            case R.id.txt_return://返回按钮
                finish();
                break;
        }
    }
}
